package com.songshu.e.dubbo.api.service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.songshu.e.dubbo.api.vo.Pagination;
import com.songshu.e.dubbo.api.vo.TableResult;
import com.songshu.e.dubbo.server.api.ApiHouseResourcesService;
import com.songshu.e.dubbo.server.pojo.HouseResources;
import com.songshu.e.dubbo.server.vo.PageInfo;
import org.springframework.stereotype.Service;

@Service
public class HouseResourcesService {

    @Reference(version = "1.0.0")//远程注入dubbo提供的service
    private ApiHouseResourcesService apiHouseResourcesService;

    //添加房源
    public boolean save(HouseResources houseResources){

        return apiHouseResourcesService.saveHouseResources(houseResources) == 1;
    }

    //查询房源列表
    public TableResult<HouseResources> queryList(HouseResources houseResources, Integer currentPage, Integer pageSize) {
        PageInfo<HouseResources> pageInfo = this.apiHouseResourcesService.
                queryHouseResourcesList(currentPage, pageSize, houseResources);

        return new TableResult<HouseResources>(pageInfo.getRecords(), new Pagination(currentPage, pageSize, pageInfo.getTotal()));
    }

    //根据id查找房源
    public HouseResources queryHouseResourcesById(Long id){
        return apiHouseResourcesService.queryHouseResourcesById(id);
    }

    //修改房源
    public boolean update(HouseResources houseResources){
        return apiHouseResourcesService.updateHouseResources(houseResources);
    }
}
